{extend name="platform/base" /}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 基本设置 </header>
	<div class="panel-body">
	<form class="form-horizontal" id="form" name="form">
		<div class="form-group">
                                            <label class="col-sm-2 control-label">是否开启三级分销</label>
                                            <div class="col-sm-4">
                                                <label class="switch">
                                                    <input id="is_distribution_enable" type="checkbox" {eq name="shop_config_info.is_distribution_enable" value="1"}checked{/eq}>
                                                    <span></span> </label>
                                                    <span class="help-inline"  style="color: #999999">三级分销设置总开关</span>
                                            </div>
                                        </div>
                                        
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
                                            <label class="col-sm-2 control-label">推广员申请是否需要审核</label>
                                            <div class="col-sm-7">
                                                <label class="switch">
                                                    <input id="is_distribution_audit" type="checkbox" {eq name="shop_config_info.is_distribution_audit" value="1"}checked{/eq}>
                                                    <span></span> </label>
                                                    <span class="help-inline" style="color: #999999">会员成为推广员的申请信息是否需要审核，如需注册的会员自动成为推广员将推广员申请、推广员申请审核关闭即可</span>
                                            </div>
                                        </div>
            <div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
                                            <label class="col-sm-2 control-label">推广员是否需要申请</label>
                                            <div class="col-sm-4">
                                                <label class="switch">
                                                    <input id="is_distribution_start" type="checkbox" {eq name="shop_config_info.is_distribution_start" value="1"}checked{/eq}>
                                                    <span></span> </label>
                                                    <span class="help-inline" style="color: #999999">普通会员想要成为推广员是否需要进行申请</span>
                                            </div>
                                        </div>
            <div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">分销佣金比率（%）</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="distribution_rate" value="{$shop_config_info.distribution_rate}" >
				</div>
				<p class="error" style="display:none;">请输入大于0小于等于100的两位的数值,最多保留俩位小数！</p>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">区域代理佣金比率（%）</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="agent_rate" value="{$shop_config_info.agent_rate}">
				</div>
				<p class="error" style="display:none;">请输入大于0小于等于100的两位的数值，最多保留俩位小数！</p>
			</div>
          <div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="modifyShopConfigIsDistribution()" class="btn btn-primary">保存</a>
				</div>
			</div>                              
	</form>
	</div>
</section>
<script src="__STATIC__/js/limit_input_digit.js"></script>
<script>		
function modifyShopConfigIsDistribution(){
	if($("#is_distribution_enable").prop("checked")){
		var is_open = 1;
	}else{
		var is_open = 0;
	}
	if($("#is_distribution_audit").prop("checked")){
		var is_audit = 1;
	}else{
		var is_audit = 0;
	}
	if($("#is_distribution_start").prop("checked")){
		var is_start = 1;
	}else{
		var is_start = 0;
	}
	
	var reg = /(?!^0\.0?0$)^[0-9][0-9]?(\.[0-9]{1,2})?$|^100$/;
	var distribution_rate = $("#distribution_rate").val();
	var agent_rate = $("#agent_rate").val();

　 　 if(distribution_rate && !reg.test(distribution_rate)) {
	　　　　$("#distribution_rate").parent().next('.error').show();
		  return false;
　　  }else{
	  	 $("#distribution_rate").parent().next('.error').hide();
　　  }

　     if(agent_rate && !reg.test(agent_rate)) {
	　　　　$("#agent_rate").parent().next('.error').show();
		  return false;
   }else{
	  	 $("#agent_rate").parent().next('.error').hide();
   }
	
	
	$.ajax({
		type:"post",
		url:"{:__URL('PLATFORM_MAIN/Distribution/modifyShopConfigIsDistributionOrPromoterIsAudit')}",
		data:{
			'is_open':is_open,
			'is_audit':is_audit,
			'is_start':is_start,
			'distribution_rate':distribution_rate,
			'agent_rate':agent_rate
		},
		async:true,
		success:function (data) {
			//alert(data);
			if (data["code"] > 0) {
				showMessage('success', data["message"],"{:__URL('PLATFORM_MAIN/Distribution/threeLevelDistributionConfig')}");
			}else{
				showMessage('error', data["message"]);
			}	
		}
	});
}
</script>
{/block}